package com.jm3.riscar3.commands;

import com.jm3.riscar3.core.Microcontroller;
import com.jm3.riscar3.helpers.BinaryTranslator;
import com.jm3.riscar3.interfaces.IAR3Command;
import com.jm3.riscar3.memory.Memory;
import com.jm3.riscar3.memory.Register;

public class STAaddr implements IAR3Command {

	private final String OpCode = "01101";
	private Register Accumulator;
	private Memory memory;
	
	public STAaddr(Microcontroller mcu)
	{
		this.Accumulator = mcu.getCPU().getAcc();
		this.memory = mcu.getMemory();
	}
	
	@Override
	public void execute(String args) throws Exception {
		// TODO Auto-generated method stub
		
		int memLoc = BinaryTranslator.getBitValue(args.substring(3));
		memory.writeToLocation(memLoc, Accumulator.readRegister());

	}

	@Override
	public String getOpCode() {
		// TODO Auto-generated method stub
		return OpCode;
	}

}
